import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import dateOpt from '@/biz/option/date.js'
import houseOpt from '@/biz/option/house.js'
import Opt from '@/components/dt/info/Opt.js'
import dt from '@dt/dt'

let _this = null;

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [{
      title: '签约单编号',
      field: 'contractCode',
      minWidth: 150,
    },
    {
      title: '归属顾问',
      field: 'counselorName',
      minWidth: 130,
      header: {
        filter: nameOpt.create({
          key: 'counselorId',
          title: '归属顾问'
        })
      }
    },
    {
      field: 'customerName',
      minWidth: 150,
      title: '客户姓名',
      slots: {
        default: (params, h) => {
          return table.cell.btn(_this, h, {
            title: params.row.customerName,
            event: 'onLinkUser',
            data: params.row
          })
        }
      },
      header: {
        filter: {
          title: '客户姓名',
          key: 'customerName',
          placeholder: '请输入客户姓名',
          input: {},
        },
      }
    },
    {
      title: '客户手机号',
      field: 'customerPhone',
      minWidth: 150,
      header: {
        filter: {
          title: '客户手机号',
          key: 'customerPhone',
          placeholder: '请输入至少4位客户手机号',
          input: {},
          check: (val) => {
            if (val.customerPhone.length < 4) {
              _this.$Message.warning('请输入至少4位客户手机号。')
            }
            return !(val.customerPhone.length < 4)
          }
        },
      }
    },
    {
      title: '签约房源',
      field: 'roomName',
      minWidth: 150,
      header: {
        filter: houseOpt.createRoom({
          key: 'roomId',
          title: '签约房源'
        })
      }
    },
    {
      title: '面积(㎡)',
      field: 'area',
      minWidth: 130,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '签约单价(元)',
      field: 'unitPrice',
      minWidth: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '签约总价(元)',
      field: 'totalPrice',
      minWidth: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '签约日期',
      field: 'contractDate',
      minWidth: 180,
      header: {
        filter: dateOpt.range({
          title: '签约日期',
          startKey: 'contractStartDate',
          endKey: 'contractEndDate',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.contractStartDate, val
                .contractEndDate).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('签约日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.contractStartDate, val
              .contractEndDate).Y >= 2)
          }
        }),
      }
    },
    {
      title: '作废回款方式',
      field: 'receiptTypeStr',
      minWidth: 180,
    },
    {
      title: '作废金额(元)',
      field: 'universalMoney',
      minWidth: 180,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '作废日期',
      field: 'universalTime',
      minWidth: 180,
      header: {
        filter: dateOpt.range({
          title: '作废日期',
          startKey: 'universalStartTime',
          endKey: 'universalEndTime',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.universalStartTime, val
                .universalEndTime).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('作废日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.universalStartTime, val
              .universalEndTime).Y >= 2)
          }
        }),
      }
    },
    {
      title: '作废原因',
      field: 'remark',
      minWidth: 230,
    },
    {
      title: '对应回款流水编号',
      field: 'receiptNumber',
      minWidth: 180,
    },
    {
      title: '对应回款日期',
      field: 'correspondTime',
      minWidth: 180,
      header: {
        filter: dateOpt.range({
          title: '对应回款日期',
          startKey: 'correspondStartTime',
          endKey: 'correspondEndTime',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.correspondStartTime, val
                .correspondEndTime).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('对应回款日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.correspondStartTime, val
              .correspondEndTime).Y >= 2)
          }
        }),
      }
    },
    {
      title: '操作人',
      field: 'operatorName',
      minWidth: 180,
    },
    {
      title: '操作',
      fixed: 'right',
      width: 140,
      align: 'center',
      slots: {
        default: (params, h) => {
          let btns = []
          btns.push({
            title: _this.unlocking('0104030300') ? '查看' : '',
            event: 'viewFun',
            data: params.row
          })
          return table.cell.btns(_this, h, btns)
        }
      }
    }, ]
  }

}


export default Column